package com.dongge.dao;

import com.dongge.entity.Info;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import java.util.List;

/**
 * Created by Administrator on 2015/10/15.
 */
public class InfoDao {

    private SessionFactory sessionFactory;

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    private Session getSession(){
        return sessionFactory.getCurrentSession();
    }

    public void saveOrUpdate(Info info){
        getSession().saveOrUpdate(info);
    }

    public List<Info> getInfoList(){
        String hql = "from Info";
        return getSession().createQuery(hql).list();
    }

    public void delete(Info info){
        getSession().delete(info);
    }

    public Info get(Integer id){
        return (Info)getSession().get(Info.class,id);
    }
}
